"""Example for the Euler equations"""

from hogs.grids import grid1d as grid
from hogs.solvers.euler1d import EESolver
from hogs.solvers.flux.euler.eulerian_flux import GodunovFluxEulerian, \
     EulerLxf, WAFFluxEulerian

from hogs.solvers.time_step_functions import EulerEquationsTimeStep
from hogs.solvers.primitive_variable_functions import EEPrimitiveVariable
from hogs.solvers.bc.boundary_conditions import PeriodicBC 

import numpy

# parameters
gamma = 1.4

# create and initialize the grid
g = grid.Grid1D()
g.initialize(xlow=-0.5, xhigh=0.5, dx=0.0001, nb=2, nvar=3)

# construct a one dimensional solver
solver = EESolver(gamma=gamma, tf=1.0, nvar=3, grid=g)

# set the flux function
#solver.flux_function = flux.GodunovFluxEulerian(gamma=1.4)
#solver.flux_function = EulerLxf()
solver.flux_function = WAFFluxEulerian()

# set the grid for the flux function
solver.flux_function.set_grid( solver.grid )

# set the boundary condition
solver.bc = PeriodicBC()

# set the time step function
solver.time_step_function = EulerEquationsTimeStep(grid=solver.grid)

# primitive variable function
solver.primitive_variable_function = EEPrimitiveVariable(gamma=gamma,
                                                         grid=solver.grid)

# process command line 
solver.setup()

# cell centers
x = g.xc
q = g.q

# initial data for the shock tube problem
rhol = 1.0; rhor = 0.125
pl = 1.0; pr = 0.1
ul = ur = 0.0

sin = numpy.sin
pi = numpy.pi

rho = 2.0 + sin(2 * pi * x )
q[0, :] = rho

u = 1.0 + 0.1 * sin(2 * pi * x)
q[1,:] = q[0,:] * u

e = 2.5 * 1.0/rho
eh = e + 0.5 * u * u
q[2,:] = rho * eh

solver.solve()
